﻿using System;
using System.Linq;
using System.Linq.Expressions;
using Zinnia.Lite.Context;
using Zinnia.Lite.Entity;

namespace Zinnia.Lite.Repository 
{
    /// <summary>
    /// 仓储模型
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IRepository<T> where T : ZinniaObject
    {
        /// <summary>
        /// 仓储中心上下文
        /// </summary>
        IEfBaseContext Context { get; }
        /// <summary>
        /// 根据标识获取实体
        /// </summary>
        /// <param name="id">标识</param>
        /// <returns>Entity</returns>
        T Get(object id);

        /// <summary>
        ///添加实体
        /// </summary>
        /// <param name="entity">数据实体</param>
        void Add(T entity);

        /// <summary>
        /// 更新数据
        /// </summary>
        /// <param name="entity">数据实体</param>
        void Change(T entity);
        /// <summary>
        /// 修改指定实体的指定属性值
        /// </summary>
        /// <param name="entity">指定实体</param>
        /// <param name="propertys">要修改值的属性表达式</param>
        void ChangeWithProperty<TProperty>(T entity, Expression<Func<T, TProperty>> propertys);

        /// <summary>
        /// 移除数据
        /// </summary>
        /// <param name="entity">数据实体</param>
        void Remove(T entity);

        /// <summary>
        /// 获取数据表
        /// </summary>
        IQueryable<T> Table { get; }

        /// <summary>
        /// 获取不缓存数据表
        /// </summary>
        IQueryable<T> TableNoTracking { get; }
    }
}
